package testPaperFavoritesPage.jsonFavoritesPage;

import android.util.Log;

import com.example.lancooznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import testPaperFavoritesPage.FavoritesPagePaperActivity;

/**
 * Created by Administrator on 2017/9/20/020.
 */

public class FavoritesPagePaperPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;

    public FavoritesPagePaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();
        HttpOnNextListener<FavoritesPageJson> httpOnNextListener = new HttpOnNextListener<FavoritesPageJson>() {
            @Override
            public void onNext(FavoritesPageJson favoritesPageJson) {
                int totalCount = favoritesPageJson.getTotalItemCount();
                if (totalCount > 0) {
                    view.hideLoading();
                    view.loadData(favoritesPageJson);
                }else {
                    view.showNoData("无法获取收藏内容");
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        FavoritesPagePaperParam api = new FavoritesPagePaperParam(httpOnNextListener, (FavoritesPagePaperActivity)view);

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }


}